<?php
$content = file_get_contents($file);
list($update,$runFor) = explode(':', $content);

$time = time();

if ($time-$update > 12) $stopped = true;
else $stopped = false;

if ($stopped) {
	$text = "Stopped";
	$style = 'background:#fcc;color:red';
} else {
	$text = "Running";
	$style = 'background:#cfc;color:green';
}
?>
<h2 style="text-align:center">Grader status<br /><small><a href="<?php WEBROOT()?>/grader/status">(grader log)</a></small></h2>
<?php
if (isset($_GET['start']) || isset($_GET['stop'])) {
?>
<div class="success">
<?php if (isset($_GET['start'])) {
	echo 'Evaluator started. If the status below has not change yet, it probably means that your web-server user does not have sudo with no password access on ./scripts/evaluator-start.sh and ./scripts/evaluator-stop.sh.';
} else { echo 'Stop file created. It might take up to 10 seconds before the grader will be fully stopped.'; } ?>
</div>
<?php
}
?>
<div style="margin:0 auto;width:400px;text-align:center;font-size:500%;<?php echo $style?>">
<?php echo $text?>
</div>
<p style="text-align:center;font-size:300%;border:1px solid #000;background:#ccc;width:200px;margin:10px auto">
<?php 
if ($stopped) {
	echo '<a href="' . WEB_ROOT . '/grader/start">Start</a>';	
} else {
	echo '<a href="' . WEB_ROOT . '/grader/stop">Stop</a>';	
}
?>
</p>
